'use strict';

module.exports = function countSameElements(collection) {
  let arr=[];
  let obj={};

  for(let item of collection){
    if(item.length > 1){

      if(!obj[item[0]]){
         obj[item[0]] = {} ;
         obj[item[0]].name = item[0] ;
         obj[item[0]].summary = parseInt(item[2]) ; 
      }
      else if(item.length == 5){
       obj[item[0]].summary += parseInt(item.slice(2,4));
      }
      else{
        obj[item[0]].summary += parseInt(item[2]);
      }
    }
    
    else{
      if(!obj[item]){
        obj[item]={};
        obj[item].name=item;
        obj[item].summary=1;
      }
      else{
        obj[item].summary++
      }
    }
  
  }

  for(let name in obj){
    arr.push(obj[name]);
  }
return arr;
}
